// ----------------------------------------------------------------------------------
// Microsoft Developer & Platform Evangelism
// 
// Copyright (c) Microsoft Corporation. All rights reserved.
// 
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// ----------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
// ----------------------------------------------------------------------------------

#region File Description
//-----------------------------------------------------------------------------
// PauseScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
#endregion

namespace HexTD
{
	class PauseScreen : MenuScreen
	{
		#region Fields
		GameScreen backgroundScreen;
		Player human;
		//bool prevHumanIsActive;
		#endregion

		#region Initialization
		public PauseScreen(GameScreen backgroundScreen)
			: base(String.Empty)
		{
			IsPopup = true;

			this.backgroundScreen = backgroundScreen;

			// Create our menu entries.
			MenuEntry startGameMenuEntry = new MenuEntry("Return");
			MenuEntry exitMenuEntry = new MenuEntry("Quit Game");

			// Hook up menu event handlers.
			startGameMenuEntry.Selected += StartGameMenuEntrySelected;
			exitMenuEntry.Selected += OnCancel;

			// Add entries to the menu.
			MenuEntries.Add(startGameMenuEntry);
			MenuEntries.Add(exitMenuEntry);

			// Preserve the old state of the game
			//prevHumanIsActive = this.human.Catapult.IsActive;

			// Pause the game logic progress
			//this.human.Catapult.IsActive = false;

			AudioManager.PauseResumeSounds(false);
		}
		#endregion

		#region Overrides
		protected override void UpdateMenuEntryLocations()
		{
			base.UpdateMenuEntryLocations();

			foreach (var entry in MenuEntries)
			{
				var position = entry.Position;

				position.Y += 60;

				entry.Position = position;
			}
		}
		#endregion

		#region Event Handlers for Menu Items
		/// <summary>
		/// Handles "Return" menu item selection
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		void StartGameMenuEntrySelected(object sender, EventArgs e)
		{
			//human.Catapult.IsActive = prevHumanIsActive;

			if (!(human as Human).isDragging)
				AudioManager.PauseResumeSounds(true);
			else
			{
				(human as Human).ResetDragState();
				AudioManager.StopSounds();
			}

			backgroundScreen.ExitScreen();
			ExitScreen();
		}

		/// <summary>
		/// Handles "Exit" menu item selection
		/// </summary>
		/// 
		protected override void OnCancel(PlayerIndex playerIndex)
		{
			AudioManager.StopSounds();
			ScreenManager.AddScreen(new MainMenuScreen(), null);
			ExitScreen();


		}
		#endregion
	}
}
